const path = require('path')
const resolve = dir => path.join(__dirname, dir)

module.exports = config => {
  const path = resolve('../src/assets/svg')
  // 使用svg组件
  config.module.rule('svg').exclude.add(path).end()
  config.module
    .rule('icons')
    .test(/\.svg$/)
    .include.add(path)
    .end()
    .use('svg-sprite-loader')
    .loader('svg-sprite-loader')
    .options({
      symbolId: 'icon-[name]'
    })
   
  config.module
    .rule('vue')
    .use('vue-loader')
    .loader('vue-loader')
    .tap(options => {
      options.transformAssetUrls = {
        'el-avatar': 'src',
        'el-image':'src'
      }}).end()

  // 添加别名
  config.resolve.alias.set('@styles', resolve('../src/styles'))
  config.resolve.alias.set('@assets', resolve('../src/assets'))
  config.resolve.alias.set('@components', resolve('../src/components'))
  config.resolve.alias.set('@views', resolve('../src/views'))
  config.resolve.alias.set('@utils', resolve('../src/utils'))
  config.resolve.alias.set('@store', resolve('../src/store'))
  config.resolve.alias.set('@api', resolve('../src/api'))

  // 根据环境不同，执行不同的配置
  if (process.env.NODE_ENV === 'production') {
    require('./webpack.config.prod.js')(config)
  } else {
    require('./webpack.config.dev.js')(config)
  }
}
